package com.heima.exception;

public class GlobalException extends RuntimeException {

    private final int code;
    private final String message;

    /**
     * 使用枚举构造异常
     */
    public GlobalException(ErrorCode errorCode) {
        super(errorCode.getMessage());
        this.code = errorCode.getCode();
        this.message = errorCode.getMessage();
    }

    /**
     * 自定义 code 和 message
     */
    public GlobalException(int code, String message) {
        super(message);
        this.code = code;
        this.message = message;
    }

    public int getCode() {
        return code;
    }

    @Override
    public String getMessage() {
        return message;
    }
}
